package admin.action.count.createFile;

import java.io.UnsupportedEncodingException;

import teacher.bean.Project;
import tools.StringDate;
import admin.databaseToExcel.PullPorjectToExcel;

public class ProjectCreateAction {
	
	private Project project;
	private int direction;
	
	public Project getProject() {
		return project;
	}
	public void setProject(Project project) {
		this.project = project;
	}

	public int getDirection() {
		return direction;
	}
	public void setDirection(int direction) {
		this.direction = direction;
	}

	public String execute()
	{
		
		if(this.getProject()!=null)
		{
			System.out.println("姓名为:"+this.getProject().getName());
			System.out.println("姓名为:"+this.getProject().getLeader());
			if(this.getProject().getName()==null||this.getProject().getName().equals(""))
				this.getProject().setName(null);
			else
			{

					try {
						this.getProject().setName(new String(this.getProject().getName().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getProject().getSource()==null||this.getProject().getSource().equals(""))
				this.getProject().setSource(null);
			else
			{

					try {
						this.getProject().setSource(new String(this.getProject().getSource().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getProject().getLeader()==null||this.getProject().getLeader().equals(""))
				this.getProject().setLeader(null);
			else
			{

					try {
						this.getProject().setLeader(new String(this.getProject().getLeader().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getProject().getOthers()==null||this.getProject().getOthers().equals(""))
				this.getProject().setOthers(null);
			else
			{

					try {
						this.getProject().setOthers(new String(this.getProject().getOthers().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getProject().getNumber()==null||this.getProject().getNumber().equals(""))
				this.getProject().setNumber(null);
			else
			{

					try {
						this.getProject().setNumber(new String(this.getProject().getNumber().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getProject().getBeginDate()!=null)
				this.getProject().setBeginDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getProject().getBeginDate())));
			if(this.getProject().getFinishDate()!=null)
				this.getProject().setFinishDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getProject().getFinishDate())));
		}
		
		PullPorjectToExcel.projectExcel(3, this.getProject(),this.getDirection());
		return "succ";
	}

}
